<!DOCTYPE html>
<html>
<head>
    <th:block th:include="include :: headermain('互助保障系统V3')"/>
</head>
<body>
<div class="page">
    <th:block th:include="include :: top"/>

    <div class="center">
        <div class="page-content page-wrap">
            <th:block th:include="include :: left"/>
            <div class="page-wrap-container">
                <div class="page-account">
                    <div class="page-tab">
                        <a href="/unit/account">基本资料</a>
                        <a href="/unit/resetPasswordForm">登录密码</a>
                        <a class="on" href="/unit/weChat">微信绑定</a>
                    </div>
                    <div class="page-tab-content" style="display:block;">
                        <c:if test="${not empty hzUnit and not empty hzUnit.openId}">
                            <div class="page-tips success">您的账号已绑定微信，点击按钮<a class="unit-btn-unbind">解除绑定</a></div>
                        </c:if>
                        <c:if test="${not empty hzUnit and empty hzUnit.openId}">
                            <div class="page-tips error">您的账号还未绑定微信，点击按钮<a class="unit-btn-bind">绑定</a></div>
                        </c:if>
                    </div>
                    <div id="smdl-pan" style="height:327px;text-align:center;">
                        <div id="weChateImg" style="height:280px;">
                            <!-- 二维码 -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer"/>
</div>
<script src="/footerjs.js"></script>
<script src="https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js"></script>
<script>
    // 解除绑定
    $(".unit-btn-unbind").click(function () {
        layer.confirm('确定要解除绑定吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.soon.ajax({
                url: "${ctxFront}/weChatUnitLogin/weChatUnitUnbind?unitId=${hzUnit.id}",
                success: function (data) {
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.location.reload();
                    }, 1000);
                }
            });
        });
    })

    // 绑定
    $(".unit-btn-bind").click(function () {
        var obj = new WxLogin({
            self_redirect: false,
            id: "weChateImg",//要显示的地址
            appid: "wx6d3bdf8f76b1efd6",
            scope: "snsapi_login",
            redirect_uri: encodeURIComponent("/weChatUnitLogin/bindUnitWeChat"),
            state: Math.ceil(Math.random() * 1000),
            style: "black",
            href: "data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDIwMHB4O30KLmltcG93ZXJCb3ggLnRpdGxlIHtkaXNwbGF5OiBub25lO30KLmltcG93ZXJCb3ggLmluZm8ge3dpZHRoOiAyMTBweDt9Ci5pbXBvd2VyQm94IC5pY29uMzhfbXNnLnN1Y2Mge2Rpc3BsYXk6IG5vbmV9Ci5pbXBvd2VyQm94IC5pY29uMzhfbXNnLndhcm4ge2Rpc3BsYXk6IG5vbmV9Ci5pbXBvd2VyQm94IC5zdGF0dXMge3RleHQtYWxpZ246IGNlbnRlcjt9Cg=="
        });
    })
</script>
</body>
</html>
